<?php
/**
 * FastApp.
 * 8/26/24
 * @Author deepsea159
 * @Contact telegram:deepsea159
 */

use App\Exchange\Model\ExchangePair;

$config = json_decode(file_get_contents(__DIR__ . '/config.json'), true);
if ($config && $config['enabled']) {
    /*清除fd 绑定*/
    $ex = redis()->keys('ex*');
    if ($ex) redis()->del($ex);

    /*初始化交易对*/
    $pair = ExchangePair::query()->with(['pairList' => function ($query) {
        $query->with(['currency:id,symbol'])->where(['status' => 1, 'is_show' => 1])->select(['legal_id', 'currency_id']);
    }, 'currency:id,symbol'])->where(['status' => 1])->get();
    $list = [];
    foreach ($pair as $item) {
        foreach ($item->pairList as $v) {
            if (!$v->currency) continue;
            $list[$item->currency->symbol][] = $v->currency->symbol . $item->currency->symbol;
        }
        if (empty($list[$item->currency->symbol])) continue;
        $list[$item->currency->symbol] = implode(',', $list[$item->currency->symbol]);
    }
    redis()->hMSet('pair', $list);
}